package day07;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

public class homework07 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入第一个字符串:");
        String str1 = sc.next();
        System.out.println("请输入第二个字符串");
        String str2 = sc.next();
        print(str1, str2);
    }

    private static void print(String str1, String str2) {
        String regex = "[a-z0-9A-Z]+";
        boolean b = str1.matches(regex) && str2.matches(regex);
        if (!b) {
            System.out.println("输入格式不正确");
        } else {
            Map<Character, Long> map = stringtomap(str1);
            Map<Character, Long> map1 = stringtomap(str2);
            resultback(map, map1);
        }
    }

    private static void resultback(Map<Character, Long> map, Map<Character, Long> map1) {
        Set<Map.Entry<Character, Long>> s1 = map.entrySet();
        Set<Map.Entry<Character, Long>> s2 = map1.entrySet();
        Long count= 0L;
        boolean sym=true;
            m1:for (Map.Entry<Character, Long> e2: s2) {
                int index= 0;
                for (Map.Entry<Character, Long> e1: s1) {
                    if (e2.getKey()!=e1.getKey()){
                        index++;
                    }else if(e2.getKey()==e1.getKey()){
                        if (e2.getValue()>e1.getValue()) {
                            System.out.println("NO");
                            sym=false;
                            break;
                        }else {
                            continue m1;
                        }
                    }
                    if (index == map.size()){
                        System.out.println("NO");
                        sym=false;
                        break;
                    }
                }
            }
            if(sym){
                for (Map.Entry<Character, Long> entry:s1
                ) {
                    count+=entry.getValue();
                }for (Map.Entry<Character, Long> entry:s2
                ) {
                    count-=entry.getValue();
                }
                System.out.println("Yes "+count);
            }
    }

    private static Map<Character, Long> stringtomap(String str) {
        ArrayList<Character> list = new ArrayList<>();
        for (int i = 0; i < str.length(); i++) {
            list.add(str.charAt(i));
        }
        Map<Character, Long> map = list.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
        System.out.println(map);
        return map;
    }
}
